/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public: 

    bool _iscompare(TreeNode* left ,TreeNode* right)
    {
        if (left == nullptr && right!=nullptr)
        {
            return false;
        }
        else if(left == nullptr && right == nullptr)
        {
            return true;
        }
        else if (left != nullptr && right == nullptr)
        {
            return false;
        }
        else if (left->val != right->val)
        {
            return false;
        }

        bool outside = _iscompare(left->left , right->right);
        bool inside = _iscompare(left->right , right->left);
        bool issame = inside & outside;
        return issame;
    } 
    bool isSymmetric(TreeNode* root) 
    {
        return _iscompare(root->left , root->right);
    }
};
